package com.pearadmin.modules.sys.controller.manage;

import com.pearadmin.common.constant.ControllerConstant;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

/**
 * @author: Mr.ling
 * @data: 2021/12/20
 * @apiNote
 */
@RestController
@Api(tags = {"报表入口"})
@RequestMapping(ControllerConstant.REPORT_WORK_PREFIX)
public class ReportController {

    private String prefix = "report/";

    @GetMapping("operate/manage")
    @ApiOperation(value = "各工区换极管理")
    @PreAuthorize("hasPermission('/report/operate/manage','report:operate:manage')")
    public ModelAndView operateManage() {
        return jumpPage(prefix + "operate/operateManage");
    }

    @GetMapping("operate/manage2")
    @ApiOperation(value = "换极记录表")
    @PreAuthorize("hasPermission('/report/operate/manager2','report:operate:manage2')")
    public ModelAndView detailManage() {
        return jumpPage(prefix + "operate/detailManage");
    }

    @GetMapping("operate/detailOperateManage")
    @ApiOperation(value = "换极量明细表")
    @PreAuthorize("hasPermission('/report/operate/detailOperateManage','report:operate:detailOperateManage')")
    public ModelAndView detailOperateManage() {
        return jumpPage(prefix + "operate/detailOperateManage");
    }


    @GetMapping("clean/view")
    @ApiOperation(value = "残阳极清理一览")
    @PreAuthorize("hasPermission('/report/clean/view','report:clean:view')")
    public ModelAndView anodeCleanView() {
        return jumpPage(prefix + "clean/view");
    }

    @GetMapping("anode/defect")
    @ApiOperation(value = "导杆组缺陷变化趋势")
    @PreAuthorize("hasPermission('/report/anode/defect','report:anode:defect')")
    public ModelAndView anodeClean() {
        return jumpPage(prefix + "anode/defect");
    }

    @GetMapping("anode/fixStatistics")
    @ApiOperation(value = "导杆组检修量统计")
    @PreAuthorize("hasPermission('/report/anode/fixStatistics','report:anode:fixStatistics')")
    public ModelAndView fixStatistics() {
        return jumpPage(prefix + "anode/fixStatistics");
    }

    @GetMapping("inventory/countChange")
    @ApiOperation(value = "库存量变化")
    @PreAuthorize("hasPermission('/report/inventory/countChange','report:inventory:countChange')")
    public ModelAndView countChange() {
        return jumpPage(prefix + "inventory/countChange");
    }

    @GetMapping("block/manage")
    @ApiOperation(value = "阳极碳块管理")
    @PreAuthorize("hasPermission('/report/block/manage','report:block:manage')")
    public ModelAndView blockManage() {
        return jumpPage(prefix + "block/manage");
    }

    @GetMapping("casting/productionNum")
    @ApiOperation(value = "生产量管理")
    @PreAuthorize("hasPermission('/report/casting/productionNum','report:casting:productionNum')")
    public ModelAndView castingProductionNum() {
        return jumpPage(prefix + "casting/stockQueryReport");
    }

    @GetMapping("inventory/countStock")
    @ApiOperation(value = "库存量报表")
    @PreAuthorize("hasPermission('/report/inventory/countStock','report:inventory:countStock')")
    public ModelAndView stockQueryReport() {
        return jumpPage(prefix + "inventory/stockOutQuantity");
    }


    @GetMapping("inventory/outManage")
    @ApiOperation(value = "出库量管理")
    @PreAuthorize("hasPermission('/report/inventory/outManage','report:inventory:outManage')")
    public ModelAndView invOutManage() {
        return jumpPage(prefix + "inventory/outManage");
    }

    @GetMapping("inventory/inCount")
    @ApiOperation(value = "入库量管理")
    @PreAuthorize("hasPermission('/report/inventory/inCount','report:inventory:inCount')")
    public ModelAndView inCount() {
        return jumpPage(prefix + "inventory/inCount");
    }

    @GetMapping("inventory/outManage2")
    @ApiOperation(value = "出库量查询")
    @PreAuthorize("hasPermission('/report/inventory/outManage2','report:inventory:outManage2')")
    public ModelAndView inventoryOutManage2() {
        return jumpPage(prefix + "inventory/outManage2");
    }

    @GetMapping("inventory/stockQuery")
    @ApiOperation(value = "库存量查询")
    @PreAuthorize("hasPermission('/report/inventory/stockQuery','report:inventory:stockQuery')")
    public ModelAndView stockQuery() {
        return jumpPage(prefix + "inventory/stockQuery");
    }

    @GetMapping("fix/history")
    @ApiOperation(value = "导杆组检修历史查询")
    @PreAuthorize("hasPermission('/report/fix/history','report:fix:history')")
    public ModelAndView fixHistory() {
        return jumpPage(prefix + "fix/history");
    }

    @GetMapping("order/process")
    @ApiOperation(value = "工单流程查询")
    @PreAuthorize("hasPermission('/report/order/process','report:order:process')")
    public ModelAndView orderProcess() {
        return jumpPage(prefix + "order/process");
    }

    // 首页报表
    @GetMapping("index")
    @ApiOperation(value = "首页报表")
    @PreAuthorize("hasPermission('/report/index','report:index')")
    public ModelAndView index() {
        return jumpPage(prefix + "index");
    }

    /**
     * 页面跳转
     */
    public ModelAndView jumpPage(String path) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName(path);
        return modelAndView;
    }

    /**
     * 带参数的页面跳转
     */
    public ModelAndView jumpPage(String path, Map<String, ?> params) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName(path);
        modelAndView.addAllObjects(params);
        return modelAndView;
    }
}
